package com.mp.approvalreq.service.impl;

import com.mp.approvalreq.dao.*;
import com.mp.approvalreq.dao.impl.*;
import com.mp.approvalreq.entity.*;
import com.mp.approvalreq.entity.common.Constants;
import com.mp.approvalreq.entity.dto.RedPointDTO;
import com.mp.approvalreq.service.RedPointServiceServant;
import com.mp.approvalreq.util.*;
import com.mp.user.entity.User;
import com.plusmoney.exception.RpcServerLogicalException;
import com.plusmoney.jdbc.util.DBUtils;
import com.plusmoney.util.Utils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;

public class RedPointServantImpl implements RedPointServiceServant {

    private static final Logger logger = LoggerFactory.getLogger(RedPointServantImpl.class);

    @Override
    public List<NewRedPoint> getRedPointByType(User user, String type) throws Throwable {
        Connection connection = DBUtils.getConnection(DbName.APPROVALREQ);
        try {
            RedDao redDao = new RedDaoImpl(connection);
            FlowDao flowDao = new FlowDaoImpl(connection);
            ParticipantDao participantDao = new ParticipantDaoImpl(connection);
            Map<String, List<Integer>> redMap = getRedMap(user, redDao);

            List<NewRedPoint> redPoints = new ArrayList<>();
            switch (type) {
                case Constants.RED_TYPE_APPROVED:
                    redPoints.add(getNeedMyApprovedRedByType(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao, type));
                    redPoints.add(getMyApprovedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao));
                    break;
                case Constants.RED_TYPE_APPLY:
                    redPoints.add(getMyApplyApproval(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    redPoints.add(getMyApply(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    break;
                case Constants.RED_TYPE_PARTICIPANT:
                    List<Integer> redPointIds = participantDao.selectUnReadRequestIds(user.getCompanyId(), user.getCompanyInfoId());
                    redPoints.add(getMyParticipateNotApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds, participantDao));
                    redPoints.add(getMyParticipateApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds, participantDao));
                    break;
                case Constants.RED_TYPE_CC_TIME:
                    redPoints.add(getCcToMeRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    redPoints.add(getArchivedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    break;
                case Constants.RED_TYPE_ONE:
                    redPoints.add(getNeedMyApprovedRedByType(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao, type));
                    break;
                case Constants.RED_TYPE_TWO:
                    redPoints.add(getMyApprovedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao));
                    break;
                case Constants.RED_TYPE_THREE:
                    redPoints.add(getMyApplyApproval(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    break;
                case Constants.RED_TYPE_FOUR:
                    redPoints.add(getMyApply(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    break;
                case Constants.RED_TYPE_FIVE:
                    List<Integer> redPointIds1 = participantDao.selectUnReadRequestIds(user.getCompanyId(), user.getCompanyInfoId());
                    redPoints.add(getMyParticipateNotApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds1, participantDao));
                    break;
                case Constants.RED_TYPE_SIX:
                    List<Integer> redPointIds2 = participantDao.selectUnReadRequestIds(user.getCompanyId(), user.getCompanyInfoId());
                    redPoints.add(getMyParticipateApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds2, participantDao));
                    break;
                case Constants.RED_TYPE_SEVEN:
                    redPoints.add(getCcToMeRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    break;
                case Constants.RED_TYPE_EIGHT:
                    redPoints.add(getArchivedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
                    break;
                default:
                    throw new RpcServerLogicalException(1, "错误的参数类型");
            }

            return redPoints;
        } catch (Throwable e) {
            throw ErrorUtils.throwError(e, logger);
        } finally {
            DBUtils.release(connection);
        }
    }

    @Override
    public List<NewRedPoint> getAllTopicRedPoint(User user) throws Throwable {
        Connection connection = DBUtils.getConnection(DbName.APPROVALREQ);
        try {
            RedDao redDao = new RedDaoImpl(connection);
            FlowDao flowDao = new FlowDaoImpl(connection);
            ParticipantDao participantDao = new ParticipantDaoImpl(connection);

            Map<String, List<Integer>> redMap = getRedMap(user, redDao);

            List<NewRedPoint> redPoints = new ArrayList<>();

            // 待我处理红点
            redPoints.add(getNeedMyApprovedRedByType(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao, Constants.RED_TYPE_APPROVED));

            // 我处理的红点
            redPoints.add(getMyApprovedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao));

            // 我申请待处理的红点
            redPoints.add(getMyApplyApproval(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            // 获取我申请的已处理
            redPoints.add(getMyApply(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            // 获取我参与的未处理
            List<Integer> redPointIds = participantDao.selectUnReadRequestIds(user.getCompanyId(), user.getCompanyInfoId());
            redPoints.add(getMyParticipateNotApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds, participantDao));

            // 获取我参与的已处理
            redPoints.add(getMyParticipateApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds, participantDao));

            // 抄送我未读的
            redPoints.add(getCcToMeRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            // 我已归档有红点
            redPoints.add(getArchivedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            return redPoints;
        } catch (Throwable e) {
            throw ErrorUtils.throwError(e, logger);
        } finally {
            DBUtils.release(connection);
        }
    }

    @Override
    public NewRedPoint getRedPoints(User user) throws Throwable {
        Connection connection = DBUtils.getConnection(DbName.APPROVALREQ);
        try {
            RedDao redDao = DaoFactory.getRedDao(connection);
            FlowDao flowDao = new FlowDaoImpl(connection);
            ParticipantDao participantDao = new ParticipantDaoImpl(connection);

            Map<String, List<Integer>> redMap = getRedMap(user, redDao);

            List<NewRedPoint> redPoints = new ArrayList<>();
            redPoints.add(getNeedMyApprovedRedByType(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao, Constants.RED_TYPE_ZERO));

            redPoints.add(getMyApprovedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, flowDao));

            redPoints.add(getMyApplyApproval(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            redPoints.add(getMyApply(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));
            List<Integer> redPointIds = participantDao.selectUnReadRequestIds(user.getCompanyId(), user.getCompanyInfoId());
            logger.info("新参与红点:{}", redPointIds);

            redPoints.add(getMyParticipateNotApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds, participantDao));

            redPoints.add(getMyParticipateApproved(user.getCompanyId(), user.getCompanyInfoId(), redMap, redPointIds, participantDao));

            redPoints.add(getCcToMeRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            redPoints.add(getArchivedRed(user.getCompanyId(), user.getCompanyInfoId(), redMap, redDao));

            NewRedPoint totalRed = new NewRedPoint();
            for (NewRedPoint redPoint : redPoints) {
                totalRed.setSmallRed(totalRed.getSmallRed() + redPoint.getSmallRed());
                totalRed.setBigRed(totalRed.getBigRed() + redPoint.getBigRed());
            }
            totalRed.setType(Constants.RED_TYPE_ZERO);

            return totalRed;
        } catch (Throwable e) {
            throw ErrorUtils.throwError(e, logger);
        } finally {
            DBUtils.release(connection);
        }
    }

    @Override
    public void clearRedPoint(RedPointDTO dto) throws Throwable {
        Connection connection = DBUtils.getConnection(DbName.APPROVALREQ);
        try {
            RequestDao requestDao = new RequestDaoImpl(connection);
            RedDao redDao = new RedDaoImpl(connection);
            CcDao ccDao = new CcDaoImpl(connection);
            ParticipantDao participantDao = new ParticipantDaoImpl(connection);

            Request request = requestDao.selectRequestDetailById(dto.getRequestId());
            if (Utils.isNull(request)) {
                throw new RpcServerLogicalException(1, "审批不存在");
            }
            if (!Objects.equals(dto.getCompanyId(), request.getCompanyId())) {
                throw new RpcServerLogicalException(1, "非法操作");
            }
            Set<Integer> contactIds = new HashSet<>();
            if (Utils.isNotNull(dto.getCompanyInfoId())) {
                List<MessageRead> readList = redDao.selectRequestUserRedPoint(dto.getRequestId(), dto.getCompanyInfoId());
                if (Utils.isNotEmpty(readList)) {
                    redDao.deleteUserRedPoint(dto.getRequestId(), dto.getCompanyInfoId());
                    contactIds.addAll(readList.stream().map(MessageRead::getContactId).collect(Collectors.toSet()));
                }
                if (request.getFinished() == Finished.AGREED && StringUtils.isNotBlank(request.getCc())) {
                    List<Cc> ccList = ccDao.selectCcRedPointInfo(request.getRequestDkey(), dto.getCompanyInfoId());
                    if (Utils.isNotEmpty(ccList)) {
                        ccDao.deleteRedPoint(request.getRequestDkey(), dto.getCompanyInfoId());
                        contactIds.addAll(ccList.stream().map(Cc::getCcId).collect(Collectors.toSet()));
                    }
                }
                if (StringUtils.isNotEmpty(request.getRelaPeople())) {
                    List<Participant> participants = participantDao.selectParticipateRedPointInfo(request.getRequestDkey(), dto.getCompanyInfoId());
                    if (Utils.isNotEmpty(participants)) {
                        participantDao.deleteRedPoint(request.getRequestDkey(), dto.getCompanyInfoId());
                        contactIds.addAll(participants.stream().map(Participant::getContactId).collect(Collectors.toSet()));
                    }
                }
            } else {
                List<MessageRead> readList = redDao.selectRedPointByRequestId(dto.getRequestId());
                if (Utils.isNotEmpty(readList)) {
                    redDao.deleteRedPointByRequestId(dto.getRequestId());
                    contactIds.addAll(readList.stream().map(MessageRead::getContactId).collect(Collectors.toSet()));
                }
                List<Cc> ccList = ccDao.selectCcRedPointInfo(dto.getRequestId());
                if (Utils.isNotEmpty(ccList)) {
                    ccDao.deleteRedPoint(request.getRequestDkey());
                    contactIds.addAll(ccList.stream().map(Cc::getCcId).collect(Collectors.toSet()));
                }
                List<Participant> participants = participantDao.selectParticipateRedPointInfo(dto.getRequestId());
                if (Utils.isNotEmpty(participants)) {
                    participantDao.deleteRedPoint(dto.getRequestId());
                    contactIds.addAll(participants.stream().map(Participant::getContactId).collect(Collectors.toSet()));
                }
            }
            if (Utils.isNotEmpty(contactIds)) {
                RocketUtils.pushToRefresh(request.getCompanyId(), contactIds);
            }
        } catch (Throwable e) {
            DBUtils.rollback(connection);
            throw ErrorUtils.throwError(e, logger);
        } finally {
            DBUtils.release(connection);
        }
    }

    @Override
    public void markMessageUnRead(RedPointDTO redPointDTO) throws Throwable {
        Connection connection = DBUtils.getConnection(DbName.APPROVALREQ);
        try {
            RedDao redDao = new RedDaoImpl(connection);
            CommentDao commentDao = new CommentDaoImpl(connection);

            MessageRead messageRead = redDao.selectMessageReadInfo(redPointDTO);
            if (Utils.isNull(messageRead)) {
                Comment comment = commentDao.selectCommentById(redPointDTO.getMessageId());
                messageRead = new MessageRead();
                messageRead.setMessageId(redPointDTO.getMessageId());
                messageRead.setCompanyInfoId(redPointDTO.getCompanyInfoId());
                messageRead.setCompanyId(comment.getCompanyId());
                messageRead.setContactId(redPointDTO.getContactId());
                messageRead.setCreatorId(comment.getCreateId());
                messageRead.setRequestId(redPointDTO.getRequestId());
                redDao.insertBatchRedPoints(Collections.singletonList(messageRead));
            } else {
                redDao.updateMessageUnRead(redPointDTO);
            }

        } catch (Throwable e) {
            throw ErrorUtils.throwError(e, logger);
        } finally {
            DBUtils.release(connection);
        }
    }

    private Map<String, List<Integer>> getRedMap(User user, RedDao redDao) throws Throwable {
        Map<String, List<Integer>> map = new HashMap<>();
        List<Integer> atRed = new LinkedList<>();
        List<Integer> refuseRed = new LinkedList<>();
        List<Integer> commentRed = new LinkedList<>();
        List<Integer> redList = new LinkedList<>();

        long time = System.currentTimeMillis();
        List<RedPointDTO> redPointDTOs = redDao.getUserRedPointList(user.getCompanyInfoId());
        logger.info("查红点耗时:{}", System.currentTimeMillis() - time);
        for (RedPointDTO redPointDTO : redPointDTOs) {
            Integer requestId = redPointDTO.getRequestId();
            if (redPointDTO.getAtRed() == 1) {
                atRed.add(requestId);
            } else if (redPointDTO.getRefuseRed() == 1) {
                refuseRed.add(requestId);
            }
            commentRed.add(requestId);
            redList.add(requestId);
        }

        logger.info("艾特红点: " + atRed);
        logger.info("驳回红点: " + refuseRed);
        logger.info("评论红点: " + commentRed);
        map.put(Constants.RED, redList);
        map.put(Constants.AT_RED, atRed);
        map.put(Constants.REFUSE_RED, refuseRed);
        map.put(Constants.COMMENT_RED, commentRed);

        return map;
    }


    private NewRedPoint getNeedMyApprovedRedByType(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, FlowDao flowDao, String type) throws SQLException {
        // 待我处理
        NewRedPoint redPoint = new NewRedPoint(Constants.RED_TYPE_ONE);

        long time = System.currentTimeMillis();
        List<Integer> needApproved = flowDao.selectNeedUserApproveIdsForRedPoint(companyId, companyInfoId);
        logger.info("待处理耗时:{}", System.currentTimeMillis() - time);

        if (Utils.isEmpty(needApproved)) {
            return redPoint;
        }
        // 首页红点
        if (type.equals(Constants.RED_TYPE_ZERO)) {
            redPoint.setBigRed(needApproved.size());
        } else {
            redPoint.setBigRed(ListHelper.getEqualParam(redMap.get(Constants.AT_RED), needApproved));
        }

        redPoint.setSmallRed(ListHelper.getEqualParam(redMap.get(Constants.RED), needApproved));

        logger.info("待我处理红点: " + redPoint);
        return redPoint;
    }


    private NewRedPoint getMyApprovedRed(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, FlowDao flowDao) throws SQLException {
        // 我已处理有红点
        NewRedPoint approvalRed = new NewRedPoint(Constants.RED_TYPE_TWO);
        List<Integer> redRequestIds = redMap.get(Constants.RED);
        if (Utils.isEmpty(redRequestIds)) {
            logger.info("无红点,已处理耗时:0");
            return approvalRed;
        }


        long time = System.currentTimeMillis();
        List<Integer> requestIds = flowDao.selectRequestIdsApprovedByCompanyInfoIdWithRedPoint(companyId, companyInfoId, Utils.list2string(redRequestIds));
        logger.info("已处理耗时:{}", System.currentTimeMillis() - time);
        if (Utils.isEmpty(requestIds)) {
            return approvalRed;
        }

        int bigRed = 0;
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.AT_RED), requestIds);
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.REFUSE_RED), requestIds);

        approvalRed.setBigRed(bigRed);
        approvalRed.setSmallRed(requestIds.size());

        logger.info("我处理的红点: " + approvalRed);
        return approvalRed;
    }


    private NewRedPoint getMyApplyApproval(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, RedDao redDao) throws SQLException {
        // 我申请待处理  == 红点 --> 我申请待处理有红点
        NewRedPoint redPoint = new NewRedPoint(Constants.RED_TYPE_THREE);
        List<Integer> redPointIds = redMap.get(Constants.RED);
        if (Utils.isEmpty(redPointIds)) {
            logger.info("无红点,申请待处理耗时:0");
            return redPoint;
        }

        long time = System.currentTimeMillis();
        List<Integer> myApplyRequestIds = redDao.getMyApplyInApproving(companyId, companyInfoId);
        logger.info("申请待处理耗时:{}", System.currentTimeMillis() - time);
        if (Utils.isEmpty(myApplyRequestIds)) {
            return redPoint;
        }

        List<Integer> myApplyRed = ListHelper.getEqualsNums(redPointIds, myApplyRequestIds);
        redPoint.setBigRed(ListHelper.getEqualParam(redMap.get(Constants.AT_RED), myApplyRed));
        redPoint.setSmallRed(myApplyRed.size());

        logger.info("我申请的待处理红点: " + redPoint);
        return redPoint;
    }


    private NewRedPoint getMyApply(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, RedDao redDao) throws SQLException {
        // 我申请已处理有红点
        NewRedPoint applyRed = new NewRedPoint(Constants.RED_TYPE_FOUR);
        List<Integer> redPointIds = redMap.get(Constants.RED);
        if (Utils.isEmpty(redPointIds)) {
            logger.info("无红点,申请已处理耗时:0");
            return applyRed;
        }

        long time = System.currentTimeMillis();
        List<Integer> myApplyRequestIds = redDao.getMyApplyHasApproved(companyId, companyInfoId);
        logger.info("申请已处理耗时:{}", System.currentTimeMillis() - time);

        if (Utils.isEmpty(myApplyRequestIds)) {
            return applyRed;
        }

        List<Integer> myApplyApprovedRed = ListHelper.getEqualsNums(redPointIds, myApplyRequestIds);
        int bigRed = 0;
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.AT_RED), myApplyApprovedRed);
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.REFUSE_RED), myApplyApprovedRed);

        applyRed.setBigRed(bigRed);
        applyRed.setSmallRed(myApplyApprovedRed.size());

        logger.info("我申请的已处理: " + applyRed);
        return applyRed;
    }

    private NewRedPoint getMyParticipateNotApproved(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, List<Integer> redPointIds,
                                                    ParticipantDao participantDao) throws Throwable {
        // 我参与的未处理
        NewRedPoint redPoint = new NewRedPoint(Constants.RED_TYPE_FIVE);

        long time = System.currentTimeMillis();
        List<Integer> requestIds = participantDao.selectParticipateRequestIdsByCompanyInfoId(companyId, companyInfoId, "0,-1", null, "不排序");
        logger.info("参与待处理耗时:{}", System.currentTimeMillis() - time);

        if (Utils.isEmpty(requestIds)) {
            return redPoint;
        }

        List<Integer> reds = ListHelper.getEqualsNums(redMap.get(Constants.RED), requestIds);
        if (Utils.isEmpty(reds) && Utils.isEmpty(redPointIds)) {
            return redPoint;
        }

        int bigRed = 0, smallRed = 0;
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.AT_RED), reds);
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.REFUSE_RED), reds);
        smallRed += reds.size();
        smallRed += ListHelper.getEqualParam(requestIds, redPointIds);

        redPoint.setBigRed(bigRed);
        redPoint.setSmallRed(smallRed);

        logger.info("我参与的未处理: " + redPoint);
        return redPoint;
    }

    private NewRedPoint getMyParticipateApproved(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, List<Integer> redPointIds,
                                                 ParticipantDao participantDao) throws Throwable {
        // 我参与的未处理
        NewRedPoint redPoint = new NewRedPoint(Constants.RED_TYPE_SIX);

        long time = System.currentTimeMillis();
        List<Integer> requestIds = participantDao.selectParticipateRequestIdsByCompanyInfoId(companyId, companyInfoId, "-2,1,2,3", null, "不排序");
        logger.info("参与已处理耗时:{}", System.currentTimeMillis() - time);
        if (Utils.isEmpty(requestIds)) {
            return redPoint;
        }

        List<Integer> reds = ListHelper.getEqualsNums(redMap.get(Constants.RED), requestIds);
        if (Utils.isEmpty(reds) && Utils.isEmpty(redPointIds)) {
            return redPoint;
        }

        int bigRed = 0, smallRed = 0;
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.AT_RED), reds);
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.REFUSE_RED), reds);
        smallRed += reds.size();
        smallRed += ListHelper.getEqualParam(requestIds, redPointIds);

        redPoint.setBigRed(bigRed);
        redPoint.setSmallRed(smallRed);

        logger.info("我参与的已处理: " + redPoint);
        return redPoint;
    }


    private NewRedPoint getCcToMeRed(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, RedDao redDao) throws SQLException {
        // 抄送我的
        NewRedPoint ccRed = new NewRedPoint(Constants.RED_TYPE_SEVEN);

        long time = System.currentTimeMillis();
        Map<String, List<Integer>> map = redDao.getCcToMeMap(companyId, companyInfoId);
        logger.info("抄送耗时:{}", System.currentTimeMillis() - time);

        int bigRed = 0;
        bigRed += map.get(Constants.UN_READ).size();
        bigRed += ListHelper.getEqualParam(redMap.get(Constants.AT_RED), map.get(Constants.READ));

        ccRed.setBigRed(bigRed);
        ccRed.setSmallRed(ListHelper.getEqualParam(redMap.get(Constants.RED), map.get(Constants.READ)));

        logger.info("抄送我的红点: " + ccRed);
        return ccRed;
    }

    private NewRedPoint getArchivedRed(Integer companyId, Integer companyInfoId, Map<String, List<Integer>> redMap, RedDao redDao) throws SQLException {
        // 我已归档有红点
        NewRedPoint redPoint = new NewRedPoint(Constants.RED_TYPE_EIGHT);
        List<Integer> redPointIds = redMap.get(Constants.RED);
        if (Utils.isEmpty(redPointIds)) {
            logger.info("无红点,归档耗时:0");
            return redPoint;
        }

        long time = System.currentTimeMillis();
        List<Integer> archived = redDao.getMyArchivedHasRed(companyId, companyInfoId, ListHelper.list2string(redPointIds));
        logger.info("归档耗时:{}", System.currentTimeMillis() - time);

        if (Utils.isEmpty(archived)) {
            return redPoint;
        }

        redPoint.setBigRed(ListHelper.getEqualParam(redMap.get(Constants.AT_RED), archived));
        redPoint.setSmallRed(archived.size());

        logger.info("我已归档的红点: " + redPoint);
        return redPoint;
    }

}
